Lab 00 - ROS recap
Robotics II
Poznan University of Technology, Institute of Robotics and Machine Intelligence
Laboratory 0: A recap of Robot Operating System 2 usage
Back to the course table of contents
Installation
The installation steps for ROS2 are available in the following links: ROS2 Foxy for Ubuntu 20.04, ROS Humble for Ubuntu 22.04 or ROS Jazzy for Ubuntu 24.04.
Alternatively, you can use prepared containers:
osrf/ros:foxy-desktop-full,
osrf/ros:humble-desktop-full or
osrf/ros:jazzy-desktop-full.
Basic concepts
Source: https://automaticaddison.com/ros-2-architecture-overview/
Usage
Below are some tips to remind you how to use ROS2 in the terminal.
Workspace
Frequently, all ROS2-related activities are performed in the created
directory: ~/ros2_ws/. In this example, the
~/ros2_ws/src/ subdirectory contains the project codes.
- When you want to build ROS nodes, invoke the following command from
the
~/ros2_ws/directory:
$ colcon build
- If the compilation was successful, source the environment variables. Note that you must do this for every console individually.
$ source install/setup.bash
Executions
ROS 2 nodes start automatically and discover each other.
- Run a node:
$ ros2 run <package_name> <executable>
i.e. $ ros2 run demo_nodes_cpp talker
- Launch a system:
$ ros2 launch <package_name> <launch_file.py>
i.e. $ ros2 launch demo_nodes_cpp talker_listener.launch.py
Topics
- List available topics:
$ ros2 topic list
- View information about the selected topic.
$ ros2 topic info <topic_name>
- Echo topic messages
$ ros2 topic echo <topic_name>
- Publish the topic message
$ ros2 topic pub <topic_name> <msg_type> "<message>"
for example:
$ ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.5}, angular: {z: 0.2}}"
Services
- Display a list of available services.
$ ros2 service list
- View information about the selected topic.
$ ros2 service type <service_name>
- Call up a specific service.
$ ros2 service call <service_name> <service_type> "<request>"
i.e. $ ros2 service call /reset std_srvs/srv/Empty "{}"
Tools
Rosbag
Rosbag allows you to record (rosbag record) and replay
(rosbag play) the status of your robotic system.
Rviz
Rviz allows you to visualise topics.
$ ros2 run rviz2 rviz2
Rqt_plot
Rqt_plot allows you to draw graphs for topics.
$ ros2 run rqt_plot rqt_plot
Rqt_graph
Rqt_graph allows the graphical visualisation of topical calls.
$ ros2 run rqt_graph rqt_graph